<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
	xmlns:ajax="http://www.apusic.com/jsf/ajax" renderKitId="AJAX">
	<w:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	</w:head>
	<body onload="javascript:pageOnload();" onunload="javascript:leaveCtrl();">
		<div>
			<input id="hostName" type="hidden" value="#{winlet.gui.GuiAppletBean.hostName }" />
			<input id="serverPort" type="hidden" value="#{winlet.gui.GuiAppletBean.serverPort }" />
			<input id="solution" type="hidden" value="#{winlet.gui.GuiAppletBean.solution }" />
			<input id="dataCenter" type="hidden" value="#{winlet.gui.GuiAppletBean.dataCenter }" />
			<input id="locale" type="hidden" value="#{winlet.gui.GuiAppletBean.locale }" />
			<input id="dbType" type="hidden" value="#{winlet.gui.GuiAppletBean.dbType }" />
			<input id="authPattern" type="hidden" value="#{winlet.gui.GuiAppletBean.authPattern }" />
			<input id="userName" type="hidden" value="#{winlet.gui.GuiAppletBean.userName }" />
			<input id="userPass" type="hidden" value="#{winlet.gui.GuiAppletBean.userPass }" />
			<input id="appServer" type="hidden" value="#{winlet.gui.GuiAppletBean.appServer }" />
			<input id="appSrvPort" type="hidden" value="#{winlet.gui.GuiAppletBean.appSrvPort }" />
			<input id="curOrgId" type="hidden" value="#{winlet.gui.GuiAppletBean.curOrgId }" />
			
			<input id="uiClass" type="hidden" value="#{winlet.gui.GuiAppletBean.uiClass }" />
			<input id="uiClassParam" type="hidden" value="#{winlet.gui.GuiAppletBean.uiClassParam }" />
			<input id="uiOprt" type="hidden" value="#{winlet.gui.GuiAppletBean.uiOprt }" />
			<input id="openMethod" type="hidden" value="#{winlet.gui.GuiAppletBean.openMethod }" />
		</div>
		<div id="messageDiv" style="font-size: 12px; position: absolute; left: 0; top: 0;">
		<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="350">
				<span class="processbar_label" id="statusTextLayer">
				<table>
					<tr><td class='processbar_label' id='process_messageId'></td></tr>
				</table>
				</span>
				</td>
			</tr>
			<tr>
				<td>
				<table width="600">
					<tr>
						<td align="center" width="600" style="">
						<div id="fileupdate">
						</div>
						</td>
					</tr>
					<tr>
						<td align="center" width="600">
						<div id="fileprogess">
						</div>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</div>
		<div id="appletDiv" style="font-size: 12px; position: absolute; right: 1; bottom: 100;">
		<object id="eas" name="eas" codeBase="kdtool.cab#version=6,0,0,1"
			classid="CLSID:559EBADD-17AA-4A4C-A9D4-59AD3E4A88AD"></object>
			
		<script language="javascript" type="text/javascript">
		//<![CDATA[
		var solution = document.getElementById("solution").value;
		var datacenter = document.getElementById("dataCenter").value;
		var local = document.getElementById("locale").value;
		var userName = document.getElementById("userName").value;
		var dbType = document.getElementById("dbType").value;
		var userPass = document.getElementById("userPass").value;
		var patt = document.getElementById("authPattern").value;
		var hostName = document.getElementById("hostName").value;
		var serverPort = document.getElementById("serverPort").value;
		var requestHost = hostName + "_" + serverPort;
		var appServer = document.getElementById("appServer").value;
		var appSrvPort = document.getElementById("appSrvPort").value;
		var currOrgId = document.getElementById("curOrgId").value;
		
		var uiClass = document.getElementById("uiClass").value;
		var uiClassParam = document.getElementById("uiClassParam").value;
		var uiOprt = document.getElementById("uiOprt").value;
		var openMethod = document.getElementById("openMethod").value;
		
		if (currOrgId != ''){
		    solution += ';'+ currOrgId;
		}
		
		if(appServer == null || appServer == "") {
			appServer = "tcp://" + hostName;
		}
		if(appSrvPort != "") {
			appServer += ":" + appSrvPort ;
		}
		
	 	var totalFile ;
		function eas::onload() {
			//alert("connecting..");
			//eas.Connect("localhost_6888");
		}

		function connect(){
             if (!eas.IsConnected) {
				var res = eas.Connect(requestHost);		
				return res;
	       }
		}
		
		function leaveCtrl() {
			if(eas.IsConnected)
			eas.SendMessage(5,"exit");	
		}
		
		function eas::OnMessage(id,value) {
			eas.text = "" + id + ": " + value;
			if(id=='8') {
				document.all("fileupdate").innerHTML="<span class='processbar_label'>"+value + "</span>";
			}
			else if(id=='10') {
				if(value.indexOf('T')>=0) {
					totalFile = value.substring(1,value.length);
                  	document.all("fileprogess").innerHTML="<span class='processbar_label'>"+ "0/"+totalFile + "</span>";
				  	process_messageId.innerText="您好，服务器有新版本，系统正在更新，请稍等......";
				}
				else {
					document.all("fileprogess").innerHTML="<span class='processbar_label'>"+ value+"/"+totalFile + "</span>";
					if(parseInt(value)>=parseInt(totalFile)||value=="") {
						document.all("fileprogess").innerHTML="<span class='processbar_label'>"+ "" + "</span>";;
						process_messageId.innerText="EAS业务应用系统初始化开始……";
					}
				}
			}
			else if(id=='9') {	//start success	
                //sendMessage(1,"tcp://localhost:11034");
                //setAppletState('started');
                //loginInvoke();
                setTimeout("loginInvoke()",   100); 
			} else if(id=='12') {
			    //apploader =true;
				//setIsInitEasFrame('0');
				//setLogined(false);
				//setNeedLogin('true');
			} 
            else if(value.indexOf("JSParameterProviderClassName,")<0 && (id!="5")&& (id!="1") &&(id!="0")&&(value.indexOf("com.kingdee")<0))
			{
				//alert("id:"+id+"value:"+value)
			    eval(value+";");
			}
			else {
			}
			//return "[browser]" + value;		
		}
		function sendMessage(id ,value) {
			//alert(value);
			if(!eas.IsConnected) {
				 eas.Connect(requestHost);
			}	
		    var result = eas.SendMessage(id,value);	
			//alert("send complete!");
		}
		function postMessage(id ,value) {
			eas.postMessage(id ,value);
		}
		
		function invokeFunction(uiClass,uiClassParam,uiOprt,openMethod){
			//alert(uiClass+","+uiClassParam+","+uiOprt+","+openMethod);
		    sendMessage('3',uiClass+","+uiClassParam+","+uiOprt+","+openMethod);
		}
		
		function loginInvoke() {
			//alert("login...");
            loginEasClient(solution, datacenter, local, dbType, userName, userPass, patt);
		}
		
		function showInvoke(){
			//alert("login...");
            //loginEasClient("eas", datacenter, local, dbType, userName, userPass, patt);
            //alert("show ui...");
			invokeFunction('com.kingdee.eas.basedata.assistant.client.CurrencyListUI', 'aa', '0', '0');
		}
		
		function loginEasClient(solution,dccenter,locale,dbtype,username,password,authPattern){
		
			//login Eas Client
			var keys = new Array();
		 	var values= new Array();
			var paramCount = -1 ;
		        paramCount++;
			keys[paramCount] = "type";
			values[paramCount] = "new" ;
		
			paramCount++;
			keys[paramCount] = "JSParameterProviderClassName";
			values[paramCount] = "com.kingdee.eas.cp.eip.apploader.LoginJSParameterProvider" ;
			paramCount++;
			keys[paramCount] = "solution";
			values[paramCount] = (solution=="null"?"":solution) ;
			paramCount++;
			keys[paramCount] = "dccenter";
			values[paramCount] = (dccenter=="null"?"":dccenter) ;
			paramCount++;
			keys[paramCount] = "locale";
			values[paramCount] = (locale=="null"?"":locale) ;
			paramCount++;
			keys[paramCount] = "dbtype";
			values[paramCount] = new String(dbtype=="null"?0:dbtype) ;
			paramCount++;
			keys[paramCount] = "username";
			values[paramCount] = (username=="null"?"":username) ;
			paramCount++;
			keys[paramCount] = "password";
			values[paramCount] = (password=="null"?"":password) ;
			paramCount++;
			keys[paramCount] = "authPattern";
			values[paramCount] = (authPattern =="null"?"":authPattern) ;
		
			paramCount++;
			keys[paramCount] = "returnEvent";
			var returnEventStr = "returnValuePerformedForLogin" ;
			values[paramCount] =  returnEventStr;
			
		  	invokeEasBiz(keys.join(","),values.join(","),returnEventStr);
		}
		
		function invokeEasBiz(keyStr,valStr,returnEventStr) {
			sendMessage("2",keyStr+";:;"+valStr);
		}
		
		function returnEventPerformed(event,returnValue) {
			//alert("show ui...");
			//invokeFunction('com.kingdee.eas.basedata.assistant.client.CurrencyListUI', 'aa', '0', '0');
		}
		
		function returnValuePerformedForLogin() {
		}
		
		function pageOnload() {
			connect();
	 		sendMessage(1, requestHost + "," + appServer);
	 		setTimeout("loginInvoke()",   100); 
		}
	//]]>	
	</script>
		</div>
		<div><input type="button" value="login" onclick="loginEas()" /></div>
		<div><input type="button" value="showui" onclick="showInvoke()" /></div>
	</body>
</f:view>